 function Getuser() {
     var userid = getCookie("userid");
     var token = getCookie("token");
     if (userid && token) {
         loadUserMsg(userid, token);
     }
 }
 // 判定是否需要进行用户信息加载; 
 async function loadUserMsg(id, token) {
     // 加载用户详细信息; 
     // 如果想要查询用户信息，那么我们就必须使用token秘钥; 
     // - 秘钥携带的方式就是把秘钥放在 authorization 里面， 给后端进行验证; 
     let url = "http://127.0.0.1:8888/users/info/" + id;

     let options = {
         method: "GET",
         // 把token放入到请求头之中，让后端可以验证我们的登录信息; 
         headers: {
             authorization: token
         }
     };
     let response = await fetch(url, options);

     let data = await response.json();

     renderUserMsg(data)
 }

 var userinfo = document.querySelector(".userinfo");
 var btnlogin = document.getElementById("btnlogin");
 var btnregistered = document.getElementById("btnregistered")
 var gang = document.getElementById("gang")
 var logout = document.getElementById("logout")

 function renderUserMsg(data) {
     // console.log(data);
     userinfo.innerHTML = `${data.info.nickname}`
     btnlogin.style.display = "none"
     btnregistered.style.display = "none"
     gang.style.display = "none"
     logout.style.display = "block"


 }
 var logout = document.getElementById("logout");
 logout.onclick = function() {

     var userid = getCookie("userid");
     var token = getCookie("token");

     if (userid && token) {
         logoutUser(userid, token)
     }
 }
 async function logoutUser(id, token) {

     let url = "http://127.0.0.1:8888/users/logout/" + id;

     let options = {
         method: "GET",
         // 把token放入到请求头之中，让后端可以验证我们的登录信息; 
         headers: {
             authorization: token
         }
     };
     let response = await fetch(url, options);

     let data = await response.json();

     if (data.code === 1) {

         // 成功注销之后， 我们刷新页面即可; 
         removeCookie("userid");
         removeCookie("token");

         location.reload();
     }
 }